import java.util.HashSet;

public class Solution839 {

    int[] b;

    public int numSimilarGroups(String[] strs) {
        b=new int[strs.length];
        for (int i=0;i<b.length;i++){
            b[i]=i;
        }
        for (int i=0;i<strs.length;i++){
            for (int j=i+1;j<strs.length;j++){
                if (valid(strs[i],strs[j])){
                    b[find(i)]=find(j);
                }
            }
        }
        HashSet<Integer> set=new HashSet<>();
        for (int i=0;i<b.length;i++){
            set.add(find(i));
        }
        return set.size();
    }

    private int find(int j) {
        while (b[j]!=j){
            j=b[j];
        }
        return j;
    }

    private boolean valid(String s1, String s2) {
        int count=0;
        for (int i=0;i<s1.length();i++){
            if (s1.charAt(i)!=s2.charAt(i)){
                count++;
            }
        }
        return count==2 || count==0;
    }

    public static void main(String[] args) {
        System.out.println(new Solution839().numSimilarGroups(new String[]{"tars","rats","arts","star"}));
    }
}
